package com.copm.ifm.servers.sys.controller;

import com.copm.ifm.base.api.pojo.PageDTO;
import com.copm.ifm.base.api.pojo.PageVO;
import com.copm.ifm.base.basic.ServiceResponse;
import com.copm.ifm.base.service.base.BaseController;
import com.copm.ifm.servers.sys.entity.SysServerStandardTip;
import com.copm.ifm.servers.sys.service.msg.SysServerStandardTipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author tp
 */
@Slf4j
@Api(tags = "服务通知/sys-server-tip")
@RestController
@RequestMapping("/sys-server-tip")
public class SysServerStandardTipController extends BaseController {

    @Autowired
    SysServerStandardTipService service;

    @ApiOperation("分页")
    @PostMapping("/page")
    public ServiceResponse<PageVO<SysServerStandardTip>> page(@RequestBody PageDTO<SysServerStandardTip> param) {
        PageVO<SysServerStandardTip> result = service.selectForPage(param);
        return success(result);
    }

    @ApiOperation("查询-根据by id")
    @GetMapping("/by/id")
    public ServiceResponse<SysServerStandardTip> getById(@ApiParam(value = "主键id", required = true)
                                                         @RequestParam Long id) {
        return success(service.selectById(id));
    }

    @ApiOperation("保存-save")
    @PostMapping
    public ServiceResponse<SysServerStandardTip> save(
            @RequestBody SysServerStandardTip entity) {
        service.save(entity);
        return success(entity);
    }

    @ApiOperation("修改-服务通知表update")
    @PutMapping
    public ServiceResponse<SysServerStandardTip> update(
            @RequestBody SysServerStandardTip entity) {
        service.updateEntityById(entity);
        return success(entity);
    }

    @ApiOperation("删除-根据by id")
    @DeleteMapping("/by/id")
    public ServiceResponse<?> deleteById(@ApiParam(value = "主键id", required = true)
                                         @RequestParam Long id) {
        SysServerStandardTip sysServerStandardTip = service.selectById(id);
        if (StringUtils.isEmpty(sysServerStandardTip)) {
            return fail("删除失败，无效数据");
        }
        service.updateDeleted(id);
        return success();
    }
}
